package com.sdruixinggroup.mondayb2b.widget;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sdruixinggroup.mondayb2b.R;
import com.sdruixinggroup.mondayb2b.models.Order;
import com.sdruixinggroup.mondayb2b.ui.Activities.AppraiseActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by 00029935 on 2017/12/7.
 */

public class OrderGoodView extends AbCustomHeaderView {
    @BindView(R.id.iv_pic)
    ImageView ivPic;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_count)
    TextView tvCount;
    @BindView(R.id.line)
    View line;
    @BindView(R.id.tv_praise)
    TextView tvPraise;
    @BindView(R.id.ll_praise)
    LinearLayout llPraise;
    private  int item_id;
    private int orderID = 0;
    public OrderGoodView(Context context) {
        super(context);
    }

    public OrderGoodView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public OrderGoodView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public int getInflateLayout() {
        return R.layout.order_good_view;
    }

    @Override
    public void setUpView(View view) {

    }

    //status=5
    public void setData(Order.OrdersBean.DataBean.OrderGoodsBean orderGoodsBean, int status,int id) {
        item_id = id;
        Glide.with(getContext()).load(orderGoodsBean.getGoods_pic()).error(R.drawable.order_merchandiser).into(ivPic);
        tvName.setText(orderGoodsBean.getGoods_name());
        tvPrice.setText("￥" + String.valueOf(orderGoodsBean.getPrice()));
        tvCount.setText("×" + String.valueOf(orderGoodsBean.getQuantity()));
        Log.e("HQQ","orderGoodsBean.getCommented():  "+orderGoodsBean.getCommented());
        if (status == 5) {
            if(orderGoodsBean.getCommented() == 0){
                tvPraise.setVisibility(VISIBLE);
                llPraise.setVisibility(VISIBLE);
            }else {
                tvPraise.setVisibility(GONE);
                llPraise.setVisibility(GONE);
            }
        } else {
            tvPraise.setVisibility(GONE);
            llPraise.setVisibility(GONE);
        }


        orderID = orderGoodsBean.getOrder_goods_id();
    }

    public void setLineisVisiable(boolean visiable) {
        line.setVisibility(visiable ? VISIBLE : INVISIBLE);
    }

    @OnClick(R.id.tv_praise)
    public void onViewClicked() {
        Intent intent = new Intent(getContext(), AppraiseActivity.class);
        intent.putExtra("ID",item_id);
        intent.putExtra("order_goods_id",orderID);
       getContext().startActivity(intent);
    }
}
